/***************************************************************************
 *   Copyright (C) 2008 by Łukasz Spintzyk   *
 *   lukasz.spintzyk@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef CONTROL_H
#define CONTROL_H
#include <inttypes.h>
#include <avr/interrupt.h>
#include "adconversion.h"
#include "device_opt.h"
#include "display.h"
#include "timer.h"

/*! Declarations of functions which are used to control the osciloskope and application menu.
 */


/*!Pointer on function which is executed when user press the SET button.
 *
 * Which function is executed finnaly depends on number of presses of SELECT. \see selectClicked();
 */
uint8_t (*setFunction)(int8_t, bool);

/*! Function is executed when change of VoltDiv is selected on menu and SET was pressed.
 */
uint8_t setVoltDiv(int8_t, bool AButton);

/*! Function is executed when change of TimeDiv is selected on menu and SET was pressed.
 */
uint8_t setTimeDiv(int8_t, bool AButton);

/*! Function is executed when one of Cursors is selected on menu and SET was pressed.
 */
uint8_t setCursor(int8_t, bool AButton);

//! \todo Write documentation here
/*! Function is executed ...
 */
uint8_t setState(int8_t, bool AButton);

/*! Function checks state of buttons of keyboard(Which is active), and signals when the value of Analog key is valid.
    \return 8-bit value in format [ 000 | (Analog_key valid value- 1 bit) | (4KEYS - 4 bits) ]
 */
inline uint8_t checkButtons();

/*! Function is invoked when user press SELECT button.
 */
inline void selectClicked();

//! VARIABLES 

//! Defines possible selected options in menu, used by setState function
enum selectedItem {NONE, SET_VOLT_DIV, SET_TIME_DIV,SET_CURSOR_X1,SET_CURSOR_Y1,
    SET_CURSOR_X2, SET_CURSOR_Y2,SET_CH1,SET_CH2,SET_ACDC, SET_ADD, SET_SUB,  SET_FREQ_ADJUST};


extern enum selectedItem selectNum;
//! Counts how many times SET key was pressed.
extern uint8_t setNum;
//! Indicates actual position of textCursor _
extern upoint8_t textCursorPos;

#endif
